#导包
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

#驱动
d=webdriver.Edge()
#网址
d.get('http://localhost/ranzhi/www/sys/user-login.html')
time.sleep(1)
#输入账号和密码
d.find_element(By.ID,'account').send_keys('admin')
d.find_element(By.ID,'password').send_keys('123456')
#点击登陆按钮
a1=("id",'submit')
WebDriverWait(d,5,0.5).until(expected_conditions.element_to_be_clickable(a1))
d.find_element(By.ID,'submit').click()
#点击客户管理
a2=("id",'s-menu-1')
WebDriverWait(d,5,0.5).until(expected_conditions.element_to_be_clickable(a2))
d.find_element(By.ID,'s-menu-1').click()
#切换iframe
a3=("id",'iframe-1')
WebDriverWait(d,5,0.5).until(expected_conditions.element_to_be_clickable(a3))
d.switch_to.frame(d.find_element(By.ID,'iframe-1'))
#点击产品
d.find_element(By.LINK_TEXT,'产品').click()
#点击添加产品
d.find_element(By.CLASS_NAME,'btn.btn-primary').click()
#输入名称
a4=("id",'name')
WebDriverWait(d,5,0.5).until(expected_conditions.element_to_be_clickable(a4))
d.find_element(By.ID,'name').send_keys('213214')
d.find_element(By.ID,'code').send_keys('Scp00244')
#产品线
li=d.find_element(By.ID,'line')
s1=Select(li)
s1.select_by_index(3)
#类型
ty=d.find_element(By.ID,'type')
s2=Select(ty)
s2.select_by_index(1)
#状态
st=d.find_element(By.ID,'status')
s3=Select(st)
s3.select_by_index(1)




# 附件不大
#采用二次定位
#附件1
Box1=d.find_element(By.ID,'fileBox1')
#上传附件
Box1.find_element(By.CLASS_NAME,'fileControl').send_keys('C:\\Users\\ThinkPad\\Downloads\\day01.txt')
#标题
Box1.find_element(By.NAME,'labels[]').send_keys('ydgusagfy')
#添加新的附件选项框
Box1.find_element(By.CLASS_NAME,'icon-plus').click()
# #删除附件
# Box1.find_element(By.CLASS_NAME,'icon-remove').click()

#附件2
Box2=d.find_element(By.ID,'fileBox2')
Box2.find_element(By.CLASS_NAME,'fileControl').send_keys('C:\\Users\\ThinkPad\\Downloads\\day01.txt')
Box2.find_element(By.NAME,'labels[]').send_keys('afsssaf')
time.sleep(3)
Box2.find_element(By.CLASS_NAME,'icon-remove').click()
time.sleep(10)



# # #附件太大
# #附件1
# Box1=d.find_element(By.ID,'fileBox1')
# file1=Box1.find_element(By.CLASS_NAME,'form-control.file-wrapper').send_keys('d:\\tools\\VMware-workstation-full-17.6.3-24583834.exe')
# #切换到提示框
# alter1=d.switch_to.alert
# alter1.accept()

#标题
d.find_element(By.CLASS_NAME,'form-control').send_keys('ydgusagfy')


a5=("id",'submit')
WebDriverWait(d,5,0.5).until(expected_conditions.element_to_be_clickable(a5))
d.find_element(By.ID,'submit').click()

a6=('class name','reloadDeleter')
input=WebDriverWait(d,5,0.5).until(expected_conditions.presence_of_element_located(a6))
timestr = time.strftime("%Y-%m-%d_%H-%M-%S",time.localtime())
d.get_screenshot_as_file(f"d:\\product{timestr}.png")

#退到默认frame
d.switch_to.default_content()

#签退
d.find_element(By.CLASS_NAME,'sign.signout').click()
time.sleep(3)








